package com.zhiyou100.loans.service.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import com.zhiyou100.loans.dao.TypesDao;
import com.zhiyou100.loans.dao.impl.TypesDaoImpl;
import com.zhiyou100.loans.model.Types;
import com.zhiyou100.loans.service.TypesService;

import net.sf.json.JSONArray;

public class TypeServiceImpl implements TypesService {
	TypesDao td = new TypesDaoImpl();
	
	@Override
	public JSONArray select() {
		ResultSet rs = td.select();
		ArrayList<Types> list = new ArrayList<>();
		//把结果集转换为集合
		try {
			while(rs.next()){
				Types t = new Types();
				t.setId(rs.getInt("id"));
				t.setName(rs.getString("name"));
				list.add(t);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		//把集合转换为jsonArray对象
		return JSONArray.fromObject(list);
	}

}
